package com.itqf.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description:  第2步，编写定时任务job类
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/7
 * @Time: 上午9:51
 */
@Component
public class MyElasticJob implements SimpleJob {

    @Override
    public void execute(ShardingContext shardingContext) {
        //System.out.println("helloworld");
        //System.out.println(shardingContext.getShardingItem());
        switch (shardingContext.getShardingItem()) {
            case 0:
                // do something by sharding item 0
                System.out.println(Thread.currentThread().getName()+":"+
                "任务0执行。。。"+new SimpleDateFormat("yyyy-MM-dd hh:mm:ss SSS").format(new Date()));

                break;
            case 1:
                // do something by sharding item 1
                System.out.println(Thread.currentThread().getName()+":"+
                        "任务1执行。。。"+new SimpleDateFormat("yyyy-MM-dd hh:mm:ss SSS").format(new Date()));

                break;
            case 2:
                // do something by sharding item 2
                System.out.println(Thread.currentThread().getName()+":"+
                        "任务2执行。。。"+new SimpleDateFormat("yyyy-MM-dd hh:mm:ss SSS").format(new Date()));

                break;
            // case n: ...
        }

    }
}
